package com.claimSettlement.controller;

import com.claimSettlement.pojo.CheLoss;
import com.claimSettlement.pojo.LossDetermination;
import com.claimSettlement.pojo.RenLoss;
import com.claimSettlement.pojo.WuLoss;
import com.claimSettlement.service.CheLossService;
import com.claimSettlement.service.LossDeterminationService;
import com.claimSettlement.service.RenLossService;
import com.claimSettlement.service.WuLossService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 定损控制层
 * 曹文韬
 */
@RestController
@CrossOrigin
@RequestMapping("/surveyLoss")
public class LossDeterminationController {
    @Resource
    LossDeterminationService lossDeterminationService;

    @Resource
    CheLossService cheLossService;

    @Resource
    WuLossService wuLossService;

    @Resource
    RenLossService renLossService;

    @RequestMapping(value = "/insLossDetermination", method = RequestMethod.POST)
    public int insLossDetermination(@RequestBody LossDetermination lossDetermination){
        if(lossDeterminationService.insLossDetermination(lossDetermination) > 0){
            return lossDeterminationService.selectZuiId();
        }
        return 0;
    }

    @RequestMapping("/getLossDeterminationByUserId")
    public LossDetermination getLossDeterminationByUserId(String caseId){
        return lossDeterminationService.getLossDeterminationByUserId(caseId);
    }

    @RequestMapping("/updateLossState")
    public Integer updateLossState(@RequestBody Map<String,Integer>map) {
        return lossDeterminationService.updateLossState(map);
    }
    @RequestMapping(value = "/delLossDetermination",produces = "text/html;charset=UTF-8")
    public String delLossDetermination(String caseId){
        return lossDeterminationService.delLossDetermination(caseId) > 0 ? "成功":"失败";
    }

    @RequestMapping(value = "/updLossDetermination", method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
    public String updLossDetermination(@RequestBody LossDetermination lossDetermination){
        return lossDeterminationService.updLossDetermination(lossDetermination) > 0 ? "成功":"失败";
    }

    @RequestMapping(value = "/insCheLoss", method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
    public String insCheLoss(@RequestBody CheLoss cheLoss){
        return cheLossService.insCheLoss(cheLoss) > 0 ? "成功":"失败";
    }

    @RequestMapping(value = "/insWuLoss", method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
    public String insWuLoss(@RequestBody WuLoss wuLoss){
        return wuLossService.insWuLoss(wuLoss) > 0 ? "成功":"失败";
    }

    @RequestMapping(value = "/insRenLoss", method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
    public String insRenLoss(@RequestBody RenLoss renLoss){
        return renLossService.insRenLoss(renLoss) > 0 ? "成功":"失败";
    }

    @RequestMapping("/getCheLoss")
    public List<CheLoss> getCheLoss(String caseId){
        return lossDeterminationService.getCheLoss(caseId);
    }

    @RequestMapping("/getWuLoss")
    public List<WuLoss> getWuLoss(String caseId){
        return lossDeterminationService.getWuLoss(caseId);
    }

    @RequestMapping("/getRenLoss")
    public List<RenLoss> getRenLoss(String caseId){
        return lossDeterminationService.getRenLoss(caseId);
    }

    @RequestMapping(value = "/updCheLoss", method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
    public String updCheLoss(@RequestBody CheLoss cheLoss){
        return cheLossService.updCheLoss(cheLoss) > 0 ? "成功":"失败";
    }

    @RequestMapping(value = "/updWuLoss", method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
    public String updWuLoss(@RequestBody WuLoss wuLoss){
        return wuLossService.updWuLoss(wuLoss) > 0 ? "成功":"失败";
    }

    @RequestMapping(value = "/updRenLoss", method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
    public String updRenLoss(@RequestBody RenLoss renLoss){
        return renLossService.updRenLoss(renLoss) > 0 ? "成功":"失败";
    }

    @RequestMapping("/getLossDataAll")
    public List<LossDetermination> getLossDataAll() {
        return lossDeterminationService.getLossDataAll();
    }
}
